package com.syq.service.impl;

import com.syq.constant.RabbitMQConstants;
import com.syq.model.StandardSubmit;
import com.syq.service.FilterChainService;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName: RouterFilterServiceImpl
 * @Description: TODO
 * @Create by: syq
 * @Date: 2022/8/27 9:52
 */

@Service("router")
public class RouterFilterServiceImpl implements FilterChainService {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private AmqpAdmin amqpAdmin;
    @Override
    public boolean strategy(StandardSubmit standardSubmit) {
        System.out.println("路由模式");
        try {
            Integer gatewayID = standardSubmit.getGatewayID();
            //队列名称
            String queueName=RabbitMQConstants.TOPIC_SMS_GATEWAY+gatewayID;
            //动态创建队列
            amqpAdmin.declareQueue(QueueBuilder.durable(queueName).build());
            rabbitTemplate.convertAndSend(queueName,standardSubmit);
        } catch (Exception e) {
            return false;
        }
        return true;
    }
}
